home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / fragment tool / initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.2 KB  |  160 lines

  1. /*
  2.     File:        Initialize.c
  3.  
  4.     Contains:    Initialization code for this application
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/5/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #include <Dialogs.h>
  25. #include <Fonts.h>
  26. #include <Windows.h>
  27. #include <Menus.h>
  28. #include <TextEdit.h>
  29. #include <Events.h>
  30. //#include <OSEvents.h>
  31. #include <Gestalt.h>
  32. #include <SegLoad.h>
  33. #include <Drag.h>
  34. #include <CodeFragments.h>
  35.  
  36. #ifndef __FRAGMENTTOOL__
  37.     #include "FragmentTool.h"
  38. #endif
  39.  
  40. #ifndef __MENUSTUFF__
  41.     #include "MenuStuff.h"
  42. #endif
  43.  
  44. #ifndef __UTILITIES__
  45.     #include "Utilities.h"
  46. #endif
  47.  
  48. #ifndef __PROTOTYPES__
  49.     #include "Prototypes.h"
  50. #endif
  51.  
  52.  
  53.  
  54.  
  55. const int32 kSleepTime = 60L;
  56.  
  57.  
  58. void InitToolbox ( void )
  59. {    
  60.     InitGraf ( &qd.thePort );
  61.     InitFonts ( );
  62.     InitWindows ( );
  63.     InitMenus ( );
  64.     TEInit ( );
  65.     InitDialogs ( nil );
  66.     InitCursor ( );
  67.     
  68.     FlushEvents ( everyEvent, 0 );
  69.     
  70.     return;
  71. }
  72.  
  73.  
  74.  
  75. void InitApplication ( void )
  76. {
  77.     SetMenuBar ( GetNewMBar ( kMenuBarID ) );
  78.     AppendResMenu( GetMenuHandle( kAppleMenu ), 'DRVR' );
  79.     DrawMenuBar ( );
  80.     
  81.     if ( !CheckConfiguration ( ) )
  82.     {
  83.         AlertUser ( kNeedSystem7, 0, nil );
  84.         ExitToShell ( );
  85.     }
  86.     
  87.     gQuit = false;                          // Initialize flag that controls main event loop
  88.     
  89.     // We need to get null events often enough to blink the caret correctly
  90.     gSleepTime = (GetCaretTime ( ) < kSleepTime) ? GetCaretTime ( ) : kSleepTime;
  91.     
  92.     
  93.     InitListClickLoop ( );                // Creates the UPPs (etc) for the ClickLoop
  94.     InitDragHandlers ( );                // Creates the UPPs for the Drag Handlers
  95.     InstallAppleEventHandlers ( );        // Installs the AE handlers for the required AE
  96.     
  97.     AdjustMenus ( );
  98.     
  99.     // Create any other RoutineDescriptors we may need
  100.     gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem );
  101.     
  102.     return;
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. //
  110. // We'll limit the scope of some of our function to the current source file
  111. // by  declairing them static. Although this has limited advantages as
  112. // far as encapsulation is concerned, it can make the source code a little
  113. // more readable.
  114. //
  115. static Boolean CheckConfiguration ( void )
  116. {
  117.     long        theResult;
  118.     OSErr        theErr;
  119.     Boolean        bHasAppleEvents, bHasFSpTraps, bHasFSpStdFile, bHasCodeFragmentManager;
  120.     
  121.     
  122.     // Verify that we can run on the current configuration
  123.     
  124.     // We require AppleEvent Manager and FSSpec-based file traps and Standard File
  125.     theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
  126.     bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent)));
  127.     
  128.     theErr = Gestalt ( gestaltFSAttr, &theResult );
  129.     bHasFSpTraps = (theErr == noErr && (theResult & (1L << gestaltHasFSSpecCalls)));
  130.     
  131.     theErr = Gestalt ( gestaltStandardFileAttr, &theResult );
  132.     bHasFSpStdFile = (theErr == noErr && (theResult & (1L << gestaltStandardFile58)));
  133.     
  134.     // Ensure CFM or CFM-68K is available
  135.     theErr = Gestalt ( gestaltCFMAttr, &theResult );
  136.     bHasCodeFragmentManager = (theErr == noErr && (theResult & (1L << gestaltCFMPresent)));
  137.  
  138.     // We would also like the Drag Manager
  139.     theErr = Gestalt ( gestaltDragMgrAttr, &theResult );
  140.     gHasDragManager = (theErr == noErr && (theResult & (1L << gestaltDragMgrPresent)));
  141.  
  142.  
  143.     // It isn't enough to use Gestalt because we may not have sucessfully linked
  144.     // to the DragLib shared library. So, we also need to test one of the symbols
  145.     // against kUnresolvedSymbol to make sure we have a valid connection to it.
  146.     // Things like memory limitations to someone having the thing open with
  147.     // write permission could cause it to fail.
  148.     
  149. #if GENERATINGCFM
  150.     if ( gHasDragManager )
  151.         gHasDragManager = (InstallTrackingHandler != (void*) kUnresolvedCFragSymbolAddress);
  152. #endif
  153.     
  154.     return (bHasAppleEvents & bHasFSpTraps & bHasFSpStdFile & bHasCodeFragmentManager);
  155. }
  156.  
  157.  
  158.  
  159.  
  160.